<?php
	include_once "../library/DbConnection.php";
	include_once "../globals.php";
	include_once "../got/Movement.php";
	include_once "../Debug.php";

	class PNGEncoder
	{
	
		function __construct()
		{
			session_start();
			$this->db = new DbConnection($GLOBALS["db_server"], $GLOBALS["db_login"], $GLOBALS["db_pass"], $GLOBALS["db_name"]);
			$this->db->connect();
	     }
		
		/**
		@desc save the PNG on server
		*/
		function saveToServer ( $pInfos )
		{
			$ret		= array();
			if(!isset($_SESSION['user_id']))
				$ret["session"]= false;
			else{
				$bytearray	= $pInfos["pngstream"];
				$imageData	= $bytearray->data;
				$idimage		= $pInfos["prefix"]."_".$_SESSION['user_id'].".png";
				if(isset($pInfos["movement"]))
				{
					$instance	= new Movement();
					$datas	= array();
					$datas["movement"] = $pInfos["movement"];
					$instance->set($datas);
				}

				$success = file_put_contents($GLOBALS["users_datas"].$pInfos["scene"]."/".$idimage, $imageData);
				$ret["success"]= $success;
				$ret["session"]= true;
			}
			return $ret;
		}
	}
?>